package com.dragon.web.controller.system;

import java.text.ParseException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.dragon.common.core.controller.BaseController;
import com.dragon.common.core.domain.AjaxResult;
import com.dragon.common.core.page.TableDataInfo;
import com.dragon.common.utils.html.HtmlUtil;
import com.dragon.common.utils.html.XmlUtil;
import com.dragon.system.domain.DoubleBill;
import com.dragon.system.domain.ECYAo;
import com.dragon.system.domain.ECYVo;
import com.dragon.system.domain.SizeBill;
import com.dragon.system.service.IManagerService;

/**
 * 岗位信息操作处理
 * 
 * @author dragon
 */
@Controller
@RequestMapping("/system/manager")
public class SysManagerController extends BaseController
{
    private String prefix = "system/manager";
    
    @Autowired
    private IManagerService managerService;
    
    @GetMapping("/dggp/detail")
    public String dggpDetal()
    {
        return prefix + "/detail/dggp-detail";
    }
    
    @GetMapping("/lq/detail")
    public String lqDetal()
    {
        return prefix + "/detail/lq-detail";
    }
    
    @GetMapping("/dx/detail")
    public String dxDetal()
    {
        return prefix + "/detail/dx-detail";
    }
    
    @GetMapping("/detail/info")
    public String infoShow()
    {
        return prefix + "/detail/info-show";
    }

    @GetMapping("/dggp")
    public String dggp()
    {
        return prefix + "/dggp";
    }
    @GetMapping("/ecy")
    public String ecy()
    {
        return prefix + "/ecy";
    }
    @GetMapping("/dx")
    public String dx()
    {
        return prefix + "/dx";
    }
    @GetMapping("/bqcspf")
    public String bqcspf()
    {
        return prefix + "/bqcspf";
    }
    @GetMapping("/lq")
    public String lq()
    {
        return prefix + "/lq";
    }
    
    @PostMapping("/team/pp/list")
    @ResponseBody
    public TableDataInfo noTeam500ToHgList() {
    	List<JSONObject> list =  managerService.select500ToHgList();
    	return super.getDataTable(list);
    }
    
    @PostMapping("/team/list")
    @ResponseBody
    public AjaxResult selectHgTeamList() {
    	List<String> list =  managerService.selectHgTeamList();
    	return AjaxResult.success("查询成功", list);
    }
    
    @PostMapping("/team/pp/add")
    @ResponseBody
    public AjaxResult noTeam500ToHgAdd(String dList) {
    	int result =  managerService.select500ToHgAdd(dList.split("#"));
    	return AjaxResult.success("匹配成功", result);
    }
    
    @GetMapping("/dggp/list")
    @ResponseBody
    public AjaxResult list()
    {
    	String url = "https://trade.500.com/jczq/?playid=312&g=1";
		String spfUrl = "https://trade.500.com/static/public/jczq/newxml/pl/pl_spf_2.xml";
    	String nspfUrl = "https://trade.500.com/static/public/jczq/newxml/pl/pl_nspf_2.xml";
    	String oddsUrl = "https://www.500.com/static/public/jczq/xml/odds/odds.xml";
		BaseController baseController = new BaseController();
		String html = baseController.httpRequestToJSON(url, "GET", "gbk");
		String spfXml = baseController.httpRequestToJSON(spfUrl, "GET", "utf-8");
		String nspfXml = baseController.httpRequestToJSON(nspfUrl, "GET", "utf-8");
		String oddsXml = baseController.httpRequestToJSON(oddsUrl, "GET", "utf-8");
		try {
			List<JSONObject> list = HtmlUtil.htmlToJSONList(html);
			List<JSONObject> spfList = XmlUtil.xmlToJSONList(spfXml);
			List<JSONObject> nspfList = XmlUtil.xmlToJSONList(nspfXml);
			List<JSONObject> oddsList = XmlUtil.xmlToJsons(oddsXml);
			list = XmlUtil.packDggpData(list, spfList, nspfList, oddsList);
			return AjaxResult.success(list);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return AjaxResult.warn("未找到相关数据!");
    }
    
    @GetMapping("/ecy/list")
    @ResponseBody
    public AjaxResult ecylist()
    {
    	String url = "https://trade.500.com/jczq/?playid=312&g=2";
		String spfUrl = "https://trade.500.com/static/public/jczq/newxml/pl/pl_spf_2.xml";
    	String nspfUrl = "https://trade.500.com/static/public/jczq/newxml/pl/pl_nspf_2.xml";
    	String oddsUrl = "https://www.500.com/static/public/jczq/xml/odds/odds.xml";
		BaseController baseController = new BaseController();
		String html = baseController.httpRequestToJSON(url, "GET", "gbk");
		String spfXml = baseController.httpRequestToJSON(spfUrl, "GET", "utf-8");
		String nspfXml = baseController.httpRequestToJSON(nspfUrl, "GET", "utf-8");
		String oddsXml = baseController.httpRequestToJSON(oddsUrl, "GET", "utf-8");
		try {
			List<JSONObject> list = HtmlUtil.htmlToJSONList(html);
			List<JSONObject> spfList = XmlUtil.xmlToJSONList(spfXml);
			List<JSONObject> nspfList = XmlUtil.xmlToJSONList(nspfXml);
			List<JSONObject> oddsList = XmlUtil.xmlToJsons(oddsXml);
			list = XmlUtil.ecypackDggpData(list, spfList, nspfList, oddsList);
			return AjaxResult.success(list);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return AjaxResult.warn("未找到相关数据!");
    }
    
    @GetMapping("/size/list")
    @ResponseBody
    public List<SizeBill> sizelist()
    {
    	/*String url = "https://trade.500.com/jczq/?playid=270&g=2";
		BaseController baseController = new BaseController();
		String html = baseController.httpRequestToJSON(url, "GET", "gbk");
		try {
			List<JSONObject> list = HtmlUtil.sizehtmlToJSONList(html);
			return AjaxResult.success(list);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        return AjaxResult.warn("未找到相关数据!");*/
    	List<SizeBill> list = managerService.selectSizeList();
    	return list;
    }
    
    @GetMapping("/double/list")
    @ResponseBody
    public List<DoubleBill> doublelist()
    {
    	List<DoubleBill> list = managerService.selectDoubleList();
    	return list;
    }
    
    @PostMapping("/double")
    @ResponseBody
    public TableDataInfo doubles(ECYAo ecy)
    {
    	List<ECYVo> list = managerService.getECYList(ecy);
    	return getDataTable(list);
    }
    
//   public static void main(String[] args) {
//		String url = "https://trade.500.com/jczq/?playid=312&g=1";
//		String spfUrl = "https://trade.500.com/static/public/jczq/newxml/pl/pl_spf_2.xml";
//    	String nspfUrl = "https://trade.500.com/static/public/jczq/newxml/pl/pl_nspf_2.xml";
//    	String oddsUrl = "https://www.500.com/static/public/jczq/xml/odds/odds.xml";
//		BaseController baseController = new BaseController();
//		String html = baseController.httpRequestToJSON(url, "GET", "gbk");
//		String spfXml = baseController.httpRequestToJSON(spfUrl, "GET", "utf-8");
//		String nspfXml = baseController.httpRequestToJSON(nspfUrl, "GET", "utf-8");
//		String oddsXml = baseController.httpRequestToJSON(oddsUrl, "GET", "utf-8");
//		try {
//			List<JSONObject> list = HtmlUtil.htmlToJSONList(html);
//			List<JSONObject> spfList = XmlUtil.xmlToJSONList(spfXml);
//			List<JSONObject> nspfList = XmlUtil.xmlToJSONList(nspfXml);
//			List<JSONObject> oddsList = XmlUtil.xmlToJsons(oddsXml);
//			list = XmlUtil.packDggpData(list, spfList, nspfList, oddsList);
//		} catch (ParseException e) {
//			e.printStackTrace();
//		}
//	}
}
